#include "syscall.h"
int Lock[4];
int Condition[4];

void test_case1()
{
	WriteFormat("----------Test Case I Part I--------\n",38,0,0);
	WriteFormat("/*Bullet Proof of Distributed Lock*/\n",38,0,0);
	
	WriteFormat("1-1 Create Lock with Wrong Address of Name\n",44,0,0);
	RemoteCreateLock(-1,10);
	WriteFormat("    Create Lock should FAIL because this name address is out of virtual address \n",82,0,0);

	WriteFormat("1-2 Create Lock with extrem long name length\n",46,0,0);
	RemoteCreateLock("testname",10000000);
	WriteFormat("    Create Lock should FAIL because this name length is too long and exceed virtual address \n",94,0,0);

	WriteFormat("1-3 Acquire and Release Uncreated Lock\n",40,0,0);
	WriteFormat("    Trying to Acquire Lock 100\n",32,0,0);
	RemoteAcquireLock(100);
	WriteFormat("    Acquire Lock should FAIL because this Lock doesn't exist \n",63,0,0);
	WriteFormat("    Trying to Release Lock 100\n",32,0,0);
		RemoteReleaseLock(100);
	WriteFormat("    Release Lock should FAIL because this Lock doesn't exist \n",63,0,0);
	
	WriteFormat("1-4 Acquire and Release Lock with unreasonable index\n",60,0,0);
	WriteFormat("    Trying to Acquire Lock -1 \n",32,0,0);
		RemoteAcquireLock(-1);
	WriteFormat("    Acquire Lock should FAIL because this index is out of bound \n",66,0,0);
	WriteFormat("    Trying to Release Lock -1 \n",32,0,0);
		RemoteReleaseLock(-1);
	WriteFormat("    Release Lock should FAIL because this index is out of bound \n",66,0,0);
	WriteFormat("    Trying to Acquire Lock 10000\n",34,0,0);
		RemoteAcquireLock(10000);
	WriteFormat("    Acquire Lock should FAIL because this index is out of bound \n",66,0,0);
	WriteFormat("    Trying to Release Lock 10000\n",34,0,0);
		RemoteReleaseLock(10000);
	WriteFormat("    Release Lock should FAIL because this index is out of bound \n",66,0,0);
	
	WriteFormat("------------test end-----------\n",33,0,0);

	return;
}

void test_case2()
{
int tmp;

	WriteFormat("----------Test Case I Part II---------\n",40,0,0);
	WriteFormat("/*Bullet Proof of Distributed Condition  */\n",45,0,0);
	
	WriteFormat("2-0 Prepare Locks to be used\n",30,0,0);
	Lock[1]=RemoteCreateLock("tempLock",8);
	Condition[1]=RemoteCreateCondition("tempCondition",13);
	WriteFormat("    Lock to be used : %d    \n",30,Lock+1,1);
	WriteFormat("    Condition to be used : %d    \n",35,Condition+1,1);
	
	WriteFormat("2-1 Create Condition with Wrong Address of Name\n",49,0,0);
		RemoteCreateCondition(-1,10);
	WriteFormat("    Create Condition should FAIL because this name address is out of virtual address \n",87,0,0);

	WriteFormat("2-2 Create Condition with extrem long name length\n",51,0,0);
		RemoteCreateCondition("testname",10000000);
	WriteFormat("    Create Condition should FAIL because this name length is too long and exceed virtual address \n",99,0,0);
	
	WriteFormat("2-3 Wait, Signal and Broadcast Uncreated Condition \n",53,0,0);
	tmp = Condition[1]+100;
	WriteFormat("    Trying to Wait Condition %d\n",33,&tmp,1);
		RemoteWaitCondition(tmp,Lock[1]);
	WriteFormat("    Trying to Signal Condition %d\n",35,&tmp,1);
		RemoteSignalCondition(tmp,Lock[1]);
	WriteFormat("    Trying to Broadcast Condition %d\n",38,&tmp,1);
		RemoteBroadcastCondition(tmp,Lock[1]);
	WriteFormat("    These operations should FAIL because this Condition doesn't exist\n",71,0,0);
	

	WriteFormat("2-4 Wait, Signal and Broadcast Condition with Uncreated Lock\n",62,0,0);
	tmp = Lock[1] + 100;
	WriteFormat("    Trying to Wait Condition with Lock %d\n",43,&tmp,1);
		RemoteWaitCondition(Condition[1],tmp);
	WriteFormat("    Trying to Signal Condition with Lock %d\n",45,&tmp,1);
		RemoteSignalCondition(Condition[1],tmp);
	WriteFormat("    Trying to Broadcast Condition with Lock %d\n",48,&tmp,1);
		RemoteBroadcastCondition(Condition[1],tmp);
	WriteFormat("    These operations should FAIL because this Lock doesn't exist\n",66,0,0);
	
	WriteFormat("2-5 Wait, Signal and Broadcast Condition of Unreasonable index\n",64,0,0);
	WriteFormat("    Trying to Wait Condition -1 \n",34,0,0);
		RemoteWaitCondition(-1,Lock[1]);
	WriteFormat("    Trying to Signal Condition -1 \n",36,0,0);
		RemoteSignalCondition(-1,Lock[1]);
	WriteFormat("    Trying to Broadcast Condition -1 \n",39,0,0);
		RemoteBroadcastCondition(-1,Lock[1]);
	WriteFormat("    These operations should FAIL because this index is out of bound \n",70,0,0);
	
	WriteFormat("    Trying to Wait Condition 10000 \n",37,0,0);
		RemoteWaitCondition(10000,Lock[1]);
	WriteFormat("    Trying to Signal Condition 10000 \n",39,0,0);
		RemoteSignalCondition(10000,Lock[1]);
	WriteFormat("    Trying to Broadcast Condition 10000 \n",42,0,0);
		RemoteBroadcastCondition(10000,Lock[1]);
	WriteFormat("    These operations should FAIL because this index is out of bound \n",70,0,0);
	
	WriteFormat("2-6 Wait, Signal and Broadcast Condition with Lock of Unreasonable index\n",74,0,0);
	WriteFormat("    Trying to Wait Condition with Lock -1 \n",44,0,0);
		RemoteWaitCondition(Condition[1],-1);
	WriteFormat("    Trying to Signal Condition with Lock -1 \n",46,0,0);
		RemoteSignalCondition(Condition[1],-1);
	WriteFormat("    Trying to Broadcast Condition with Lock -1 \n",49,0,0);
		RemoteBroadcastCondition(Condition[1],-1);
	WriteFormat("    These operations should FAIL because this index is out of bound \n",70,0,0);
	WriteFormat("    Trying to Wait Condition with Lock 10000 \n",47,0,0);
		RemoteWaitCondition(Condition[1],10000);
	WriteFormat("    Trying to Signal Condition with Lock 10000 \n",49,0,0);
		RemoteSignalCondition(Condition[1],10000);
	WriteFormat("    Trying to Broadcast Condition with Lock 10000 \n",52,0,0);
		RemoteBroadcastCondition(Condition[1],10000);
	WriteFormat("    These operations should FAIL because this index is out of bound \n",70,0,0);
	
	RemoteDestroyLock(Lock[1]);
	RemoteDestroyCondition(Condition[1]);
	WriteFormat("------------test end-----------\n",33,0,0);
}
int main()
{
	test_case1();
	test_case2();
}
